package com.ysqcould.web.controller.members;


import com.ysqcould.common.annotation.Log;
import com.ysqcould.common.core.controller.BaseController;
import com.ysqcould.common.core.domain.AjaxResult;
import com.ysqcould.common.core.page.TableDataInfo;
import com.ysqcould.common.enums.BusinessType;
import com.ysqcould.common.utils.poi.ExcelUtil;
import com.ysqcould.members.domain.GroupName;
import com.ysqcould.members.service.IGroupNameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 团体会名称Controller
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@RestController
@RequestMapping("/members/name")
public class GroupNameController extends BaseController
{
    @Autowired
    private IGroupNameService groupNameService;

    /**
     * 查询团体会名称列表
     */
    @PreAuthorize("@ss.hasPermi('members:name:list')")
    @GetMapping("/list")
    public TableDataInfo list(GroupName groupName)
    {
        startPage();
        List<GroupName> list = groupNameService.selectGroupNameList(groupName);
        return getDataTable(list);
    }

    /**
     * 导出团体会名称列表
     */
    @PreAuthorize("@ss.hasPermi('members:name:export')")
    @Log(title = "团体会名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GroupName groupName)
    {
        List<GroupName> list = groupNameService.selectGroupNameList(groupName);
        ExcelUtil<GroupName> util = new ExcelUtil<GroupName>(GroupName.class);
        util.exportExcel(response, list, "团体会名称数据");
    }

    /**
     * 获取团体会名称详细信息
     */
    @PreAuthorize("@ss.hasPermi('members:name:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(groupNameService.selectGroupNameById(id));
    }

    /**
     * 新增团体会名称
     */
    @PreAuthorize("@ss.hasPermi('members:name:add')")
    @Log(title = "团体会名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GroupName groupName)
    {
        groupName.setAsId(getUserId());
        return toAjax(groupNameService.insertGroupName(groupName));
    }

    /**
     * 修改团体会名称
     */
    @PreAuthorize("@ss.hasPermi('members:name:edit')")
    @Log(title = "团体会名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GroupName groupName)
    {
        return toAjax(groupNameService.updateGroupName(groupName));
    }

    /**
     * 删除团体会名称
     */
    @PreAuthorize("@ss.hasPermi('members:name:remove')")
    @Log(title = "团体会名称", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(groupNameService.deleteGroupNameByIds(ids));
    }
}
